import cv2 as cv
import time
# cap1=cv.VideoCapture("rtsp://admin:zy123456@172.27.224.95:554")
# cap1.set()
# # cap2=cv.VideoCapture("rtsp://admin:zy123456@172.27.169.14:554")
# cutime=time.time()
# print(cv.VideoCapture("rtsp://admin:zy123456@172.27.169.14:554"))
# print(time.time()-cutime)
# print(cap2.isOpened())

import ffmpeg
import subprocess
import threading
# camera_url = "rtsp://admin:zy123456@172.27.169.14:554"
from util import get_token,get_camera_list
import requests
import json
if __name__ == '__main__':
    port_list=[5032]
    # port_list=[5001,5002,5003,5004,5005,5031,5032,5033,5034,5035]
    # port_list = [5031,5032,5033,5034,5035]
    for i in range(len(port_list)):
    # for i in range(0,10):
        gpu_id = i
        port = port_list[i]
        # url = 'http://127.0.0.1:' + str(port) + "/start"
        url =  "http://" + '10.127.38.150:' + str(port) + "/start"
        print(url)
        camera_list = get_camera_list(port)
        data = json.dumps(camera_list)
        print(data)
        while True:
            response = requests.post(url,data=data)
            if response.status_code == 200:
                break

    # port = 5002
    # url = 'http://127.0.0.1:' + str(port) + "/start"
    # camera_list = get_camera_list(port)
    # data = json.dumps(camera_list)
    # while True:
    #     response = requests.post(url, data=data)
    #     if response.status_code == 200:
    #         break